$(function() {
	//设置活动按钮
	changeActiveItem('gamePrizeList');
	//初始化列表数据
	initTable();
	savehandle();
});


function savehandle() {
	$('#alertdiv').hide();
	$('#alertdiv').savehandle({
		fieldMap : {},
		successMsg : "成功！",
		failMsg : "失败，请重试！",
		success : successCallBack
	});
}

function successCallBack() {
	refresh();
}

/**
 * 初始化表格数据
 */
function initTable() {
	$('#grid').grid({
		title : '',
		pager : true,
		tbar : '#navbar',
		store : {
			url : '/fw/game/prize_getlist.action',
			idProperty : 'gamePrizeId',
			uploadPagesize : 'rows'
		},
		pageCfg : {
			btnCount : 5
		},
		columns : [
		        {cn:'奖品名称', en:'prizeName', width : 100},
		        {cn:'奖品等级', en:'level', width : 100},
		        {cn:'中奖概率', en:'probability', width : 100, tpl: function(v) {
		        	if(v.probability && v.probability > 0)
		        		return  v.probability + "%";
		        	else
		        		return "0%";
		        }},
		        {cn:'奖品类型', en:'type', width : 100, tpl: function(v) {
		        	if(v.type == 0)
		        		return "积分";
		        	if(v.type == 1)
		        		return "红包";
		        	if(v.type == 2)
		        		return "实物";
		        }},
		        {cn:'奖品内容', en:'prizeRemark', width : 100}
				]
	});
}



function add() {
	location.href = "gamePrizeAdd.jsp";
}

function edit(){
	var ids = $('#grid').grid('getSelectedIds');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要修改的数据!',timer:2000});
		return;
	}else{
		var idsStr = ids[0];
		location.href = "gamePrizeEdit.jsp#"+idsStr;
	}
}

function del(){
	var ids = $('#grid').grid('getSelectedIds');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要删除的数据!',timer:2000});
		return;
	}else{
		var idsStr = ids.join(',');
		if(confirm("这些数据确定要删除数据？")){
			$.getJSON(
				'/fw/game/prize_del.action',
				{
					'ids':idsStr
				},
				function(data){
					$('#alertdiv').savehandle('handle',data,2000);
					refresh();
				}
			);
		}
	}
}



/**
 * 刷新
 * 
 * @return {TypeName}
 */
function refresh() {
	$('#grid').grid('load', {data : {}});
}

function findAll() {
	refresh();
}